1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : photogallery/admin/classes/class.gallerysettings.inc.php
5 : - Modulgruppe: Photogallery
6 : - Beschreibung: Galerie Einstellungen
7 : - Autor(en): Thomas Loreit <smg@newtron-game.com>
8 : +---------------------------------------------------------------------------+
9 : This program is free software; you can redistribute it and/or
10 : modify it under the terms of the GNU General Public License
11 : as published by the Free Software Foundation; either version 2
12 : of the License, or any later version.
13 : +---------------------------------------------------------------------------+
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 : +--------------------------------------------------------------------------*/
22 : /**
23 : * Speicherung und Abfrage der Galerieeinstellungen
24 : * @package eStudy.PhotoGallery
25 : * @author Thomas Loreit <smg@newtron-game.com>
26 : * @version 1.3, 18.12.2005
27 : */
28 : class GallerySettings {
29 : var $maxwidth;
30 : var $maxheight;
31 : var $maxfilesize;
32 : var $maximages;
33 : var $slidetime;
34 : /** Dieser Konstruktor lädt die Einstellungen der Klasse aus der Datenbank
35 : * oder erzeugt die Standard-Daten, wenn nichts in der Datenbank gefunden wird.
36 : */
37 : function GallerySettings() {
38 9 : global $db;
39 : //einstellungen aus datenbank laden
40 9 : $dbentry = $db->get_row("SELECT * FROM photogallery_settings WHERE course_id={$_SESSION['course']}");
41 9 : if ($dbentry) {
42 9 : $this->maxwidth = $dbentry->maxwidth;
43 9 : $this->maxheight = $dbentry->maxheight;
44 9 : $this->maxfilesize = $dbentry->maxfilesize;
45 9 : $this->maximages = $dbentry->maximages;
46 9 : $this->slidetime = $dbentry->slidetime;
47 9 : } else {
48 1 : $this->maxwidth = 1024;
49 1 : $this->maxheight = 768;
50 1 : $this->maxfilesize = 2.5;
51 1 : $this->maximages = 0;
52 1 : $this->slidetime = 10;
53 : }
54 9 : }
55 : /** Diese Funktion überprüft, ob die Eingaben in DATA_postvar gültig sind
56 : * und falls ja, dann weist sie die Daten der localval zu.
57 : *
58 : * @param localvar ist die Variable, der die Daten zugewiesen werden sollen
59 : * @param DATA_postvar ist ein Objekt von Typ Data, welches auf Gültigkeit überprüft wird
60 : */
61 : function secureAssign(&$localvar, &$DATA_postvar) {
62 2 : if ($DATA_postvar->IsValid()) $localvar = $DATA_postvar->data;
63 2 : }
64 : /** Diese Funktion überprüft ob das Formular Eingaben empfangen hat. Wenn der User
65 : * die erforderlichen Rechte besitzt werden die Enstellungen in die Datenbank geschrieben.
66 : *
67 : * Zusätzlich überprüft sich ob die neuen Eigenschaften gültig sind und innerhalb ihrer
68 : * Wertegrenzen liegen. Wenn nicht, dann werden sie zur nähesten Grenze gerundet.
69 : *
70 : */
71 : function ProcessInput() {
72 2 : if ($_SESSION['usergroup'] == ADMIN || $_SESSION['usergroup'] == DOZENT) {
73 2 : if (isset($_POST['storesettings'])) {
74 2 : $this->secureAssign($this->maxwidth, new IntegerNumberData($_POST['setting_maxwidth']));
75 2 : $this->secureAssign($this->maxheight, new IntegerNumberData($_POST['setting_maxheight']));
76 2 : $this->secureAssign($this->maxfilesize, new FloatNumberData($_POST['setting_maxfilesize']));
77 2 : $this->secureAssign($this->maximages, new IntegerNumberData($_POST['setting_maximages']));
78 2 : $this->secureAssign($this->slidetime, new IntegerNumberData($_POST['setting_slidetime']));
79 2 : $this->maxfilesize = str_replace(',', '.', $this->maxfilesize); //wieder als richtigen float speichern
80 : //checken ob die eingaben auch sinn machen
81 2 : if ($this->maxwidth < 1) $this->maxwidth = 1;
82 2 : if ($this->maxwidth > 4096) $this->maxwidth = 4096;
83 2 : if ($this->maxheight < 1) $this->maxheight = 1;
84 2 : if ($this->maxheight > 4096) $this->maxheight = 4096;
85 2 : if ($this->maxfilesize < 0.1) $this->maxfilesize = 0.1;
86 2 : if ($this->maxfilesize > 20.0) $this->maxfilesize = 20.0;
87 2 : if ($this->maximages < 0) $this->maximages = 0;
88 2 : if ($this->maximages > 9999) $this->maximages = 9999;
89 2 : if ($this->slidetime < 0) $this->slidetime = 0;
90 2 : if ($this->slidetime > 240) $this->slidetime = 240;
91 : //jetzt den ganzen shit in die DB schreiben :)
92 2 : global $db;
93 2 : $db->query("DELETE FROM photogallery_settings WHERE course_id=$_SESSION[course]"); //alten eintrag löschen
94 2 : $db->query("INSERT INTO photogallery_settings (course_id,maxwidth,maxheight,maxfilesize,maximages,slidetime) VALUES ($_SESSION[course],{$this->maxwidth},{$this->maxheight},{$this->maxfilesize},{$this->maximages},{$this->slidetime})"); //neue einstellungen eintragen
95 :
96 2 : }
97 2 : }
98 2 : }
99 : /** Ruft ProcessInput() und PrintForm() auf. Sie sollte verwendet werden, wenn das Formular ausgegeben werden
100 : * soll, denn sie Prüft somit gleich die Eingaben dafür.
101 : */
102 : function ProcessForm() {
103 1 : $this->ProcessInput();
104 1 : $this->PrintForm();
105 1 : }
106 : /** Die Funktion gibt das Formular mit den aktuellen Einstellungen aus.
107 : *
108 : * Die gespeicherten float Werte werden ins Deutsche konvertiert mit einem Komman anstatt einem
109 : * Punkt.
110 : */
111 : function PrintForm() {
112 2 : $maxfilesize = str_replace('.', ',', $this->maxfilesize); //komma anstatt punkt ausgeben
113 2 : print "<form method='post' action='".PATH_TO_ROOT.SCRIPT_NAME."'>
114 : <table width='100%' cellspacing='2' cellpadding='3'>
115 :
116 : <tr>
117 : <td class='tableCell' style='width:50%;text-align:right;'> Maximale Bildbreite</td>
118 2 : <td class='tableCell'> <p class='pForm'><input type='text' name='setting_maxwidth' value='{$this->maxwidth}' style='width:5em'/> Pixel</p> </td>
119 : </tr>
120 : <tr>
121 : <td class='tableCell' style='width:50%;text-align:right;'> Maximale Bildhöhe</td>
122 2 : <td class='tableCell'> <p class='pForm'><input type='text' name='setting_maxheight' value='{$this->maxheight}' style='width:5em'/> Pixel</p> </td>
123 : </tr>
124 : <tr>
125 : <td class='tableCell' style='width:50%;text-align:right;'> Maximale Bildgröße</td>
126 2 : <td class='tableCell'> <p class='pForm'><input type='text' name='setting_maxfilesize' value='{$maxfilesize}' style='width:5em'/> MB</p> </td>
127 : </tr>
128 : <tr>
129 : <td class='tableCell' style='width:50%;text-align:right;'> Max. Anzahl Bilder pro Album</td>
130 2 : <td class='tableCell'> <p class='pForm'><input type='text' name='setting_maximages' value='{$this->maximages}' style='width:5em'/> (0 = unbegrenzt)</p> </td>
131 : </tr>
132 : <tr>
133 : <td class='tableCell' style='width:50%;text-align:right;'> Anzeigedauer eines Bildes der Slideshow</td>
134 2 : <td class='tableCell'> <p class='pForm'><input type='text' name='setting_slidetime' value='{$this->slidetime}' style='width:5em'/> Sekunden (0 = unbegrenzt)</p> </td>
135 2 : </tr>";
136 2 : echo "<tr><td class='tableCellDark' colspan='5' style='text-align:center;'><input type='submit' name='storesettings' value='Speichern'/></td></tr>";
137 2 : echo "</table></form>";
138 2 : }
139 : /** @return Liefert die maximale Breite, die ein Bildupload haben darf */
140 : function get_maxwidth() {
141 1 : return $this->maxwidth;
142 : }
143 : /** @return Liefert die maximale Höhe, die ein Bildupload haben darf */
144 : function get_maxheight() {
145 1 : return $this->maxheight;
146 : }
147 : /** @return Liefert die maximale Dateigröße, die ein Bildupload haben darf in Bytes */
148 : function get_maxfilesize() {
149 1 : return $this->maxfilesize*1024*1024;
150 : }
151 : /** @return Liefert die maximale Anzahl Bilder, die in ein Album hochgeladen werden dürfen */
152 : function get_maximages() {
153 1 : return $this->maximages;
154 : }
155 : /** @return Liefert die Zeit in Sekunden, die ein Bild in der Slideshow angezeigt wird */
156 : function get_slidetime() {
157 1 : return $this->slidetime;
158 : }
159 : }
160 : $photosettings = new GallerySettings();
|